<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
          "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>QUnit for KJUR.crypto.DSA class 'dsa-2.0.js' or later</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>

<!-- script type="text/javascript" src="qunit.js" /script -->
<!-- link rel="stylesheet" href="qunit.css" type="text/css" media="screen" -->
<script src="http://code.jquery.com/qunit/qunit-1.11.0.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.11.0.css" type="text/css" media="screen"/>

<script src="../ext/cj/cryptojs-312-core-fix.js"></script>
<script src="../ext/cj/x64-core.js"></script>
<script src="../ext/cj/cipher-core_min.js"></script>
<script src="../ext/cj/aes_min.js"></script>
<script src="../ext/cj/tripledes_min.js"></script>
<script src="../ext/cj/enc-base64_min.js"></script>
<script src="../ext/cj/md5_min.js"></script>
<script src="../ext/cj/sha1_min.js"></script>
<script src="../ext/cj/sha256_min.js"></script>
<script src="../ext/cj/sha224_min.js"></script>
<script src="../ext/cj/sha512_min.js"></script>
<script src="../ext/cj/sha384_min.js"></script>
<script src="../ext/cj/ripemd160_min.js"></script>
<script src="../ext/cj/hmac_min.js"></script>
<script src="../ext/cj/pbkdf2_min.js"></script>

<script src="../ext/yahoo.js"></script>
<script src="../ext/jsbn.js"></script>
<script src="../ext/jsbn2.js"></script>
<script src="../ext/prng4.js"></script>
<script src="../ext/rng.js"></script>
<script src="../ext/base64.js"></script>
<script src="../ext/rsa.js"></script>
<script src="../ext/rsa2.js"></script>

<script src="../src/base64x-1.1.js"></script>
<script src="../src/asn1hex-1.1.js"></script>
<script src="../src/rsapem-1.1.js"></script>
<script src="../src/rsasign-1.2.js"></script>
<script src="../src/asn1-1.0.js"></script>
<script src="../src/crypto-1.1.js"></script>
<script src="../src/keyutil-1.0.js"></script>
<script src="../src/dsa-2.0.js"></script>
<script type="text/javascript">
<!--
$(document).ready(function(){

// key _work_dsa/d1
var p = new BigInteger("9ed327a12407c8d2dc9a6b9359fbc48f2a317504f33b48661c4b03778f55b818af219285bbcdfa60f63f96f5c3c06738d72432a36f46d6490a0fe70238517671e7abdb430c4ffb74a17fb6d0ceceee28fddb49273bcd165a520e4a9717b4d27ef06f3417df6a9ea2da35058f119ae76ac8095a2c45ee576c3dfe8253f3449a4f", 16);
var q = new BigInteger("832124c3188298f8d6dd1ad84121c2ef33a5d52b", 16);
var g = new BigInteger("711ac4053baf502aa0a09abcb7af72885495e1efb0de129d93c7bb16f0e4b80a1a10d0409ed52bcd0df0b5511f6e08f74715517e9406edd45d78f0ef15d92b27ef398ea7bf9365fa13591322149fa84635187da277f15cbc8c9a28423feb233221e5d1ad36d926d2e1e0c770f34dc04a616f55685222a9b1cf4f8ecf87c19b7e", 16);
var y = new BigInteger("8cafd9654ce51818e154613bd0b14ee974fbdffc5a19802c4301302bc854d5e17daf0d6745a4aaa8e46ff96b57c89371fa72cca12a2248821645d1ff75869a2549ad7fd110ceefea5616d00be5941036e1a2d87bbcf0bfbe6c3b1e18ba0d3b3af6d34bacf613270a0b5f67c78668e4ba5b3ec0aa28e762ea1f9f2e0167e0523b", 16);
var x = new BigInteger("73b3538660ceac98a3bf48e53f88b4e124657c21", 16);
var D1PRVP5HEX = "308201bb020100028181009ed327a12407c8d2dc9a6b9359fbc48f2a317504f33b48661c4b03778f55b818af219285bbcdfa60f63f96f5c3c06738d72432a36f46d6490a0fe70238517671e7abdb430c4ffb74a17fb6d0ceceee28fddb49273bcd165a520e4a9717b4d27ef06f3417df6a9ea2da35058f119ae76ac8095a2c45ee576c3dfe8253f3449a4f021500832124c3188298f8d6dd1ad84121c2ef33a5d52b028180711ac4053baf502aa0a09abcb7af72885495e1efb0de129d93c7bb16f0e4b80a1a10d0409ed52bcd0df0b5511f6e08f74715517e9406edd45d78f0ef15d92b27ef398ea7bf9365fa13591322149fa84635187da277f15cbc8c9a28423feb233221e5d1ad36d926d2e1e0c770f34dc04a616f55685222a9b1cf4f8ecf87c19b7e028181008cafd9654ce51818e154613bd0b14ee974fbdffc5a19802c4301302bc854d5e17daf0d6745a4aaa8e46ff96b57c89371fa72cca12a2248821645d1ff75869a2549ad7fd110ceefea5616d00be5941036e1a2d87bbcf0bfbe6c3b1e18ba0d3b3af6d34bacf613270a0b5f67c78668e4ba5b3ec0aa28e762ea1f9f2e0167e0523b021473b3538660ceac98a3bf48e53f88b4e124657c21"; // d1.prv.p5p.der
var D1PRVP8HEX = "3082014a0201003082012b06072a8648ce3804013082011e028181009ed327a12407c8d2dc9a6b9359fbc48f2a317504f33b48661c4b03778f55b818af219285bbcdfa60f63f96f5c3c06738d72432a36f46d6490a0fe70238517671e7abdb430c4ffb74a17fb6d0ceceee28fddb49273bcd165a520e4a9717b4d27ef06f3417df6a9ea2da35058f119ae76ac8095a2c45ee576c3dfe8253f3449a4f021500832124c3188298f8d6dd1ad84121c2ef33a5d52b028180711ac4053baf502aa0a09abcb7af72885495e1efb0de129d93c7bb16f0e4b80a1a10d0409ed52bcd0df0b5511f6e08f74715517e9406edd45d78f0ef15d92b27ef398ea7bf9365fa13591322149fa84635187da277f15cbc8c9a28423feb233221e5d1ad36d926d2e1e0c770f34dc04a616f55685222a9b1cf4f8ecf87c19b7e0416021473b3538660ceac98a3bf48e53f88b4e124657c21"; // d1.prv.p8p.der
var D1PUBP8HEX = "308201b73082012b06072a8648ce3804013082011e028181009ed327a12407c8d2dc9a6b9359fbc48f2a317504f33b48661c4b03778f55b818af219285bbcdfa60f63f96f5c3c06738d72432a36f46d6490a0fe70238517671e7abdb430c4ffb74a17fb6d0ceceee28fddb49273bcd165a520e4a9717b4d27ef06f3417df6a9ea2da35058f119ae76ac8095a2c45ee576c3dfe8253f3449a4f021500832124c3188298f8d6dd1ad84121c2ef33a5d52b028180711ac4053baf502aa0a09abcb7af72885495e1efb0de129d93c7bb16f0e4b80a1a10d0409ed52bcd0df0b5511f6e08f74715517e9406edd45d78f0ef15d92b27ef398ea7bf9365fa13591322149fa84635187da277f15cbc8c9a28423feb233221e5d1ad36d926d2e1e0c770f34dc04a616f55685222a9b1cf4f8ecf87c19b7e03818500028181008cafd9654ce51818e154613bd0b14ee974fbdffc5a19802c4301302bc854d5e17daf0d6745a4aaa8e46ff96b57c89371fa72cca12a2248821645d1ff75869a2549ad7fd110ceefea5616d00be5941036e1a2d87bbcf0bfbe6c3b1e18ba0d3b3af6d34bacf613270a0b5f67c78668e4ba5b3ec0aa28e762ea1f9f2e0167e0523b"; // d1.pub.p8.der
var D1CERTHEX = "308202c430820282a003020102020900fd8cc68e37232612300b0609608648016503040302301a310b3009060355040613025553310b3009060355040a0c024431301e170d3133313030323135303434345a170d3233303933303135303434345a301a310b3009060355040613025553310b3009060355040a0c024431308201b73082012b06072a8648ce3804013082011e028181009ed327a12407c8d2dc9a6b9359fbc48f2a317504f33b48661c4b03778f55b818af219285bbcdfa60f63f96f5c3c06738d72432a36f46d6490a0fe70238517671e7abdb430c4ffb74a17fb6d0ceceee28fddb49273bcd165a520e4a9717b4d27ef06f3417df6a9ea2da35058f119ae76ac8095a2c45ee576c3dfe8253f3449a4f021500832124c3188298f8d6dd1ad84121c2ef33a5d52b028180711ac4053baf502aa0a09abcb7af72885495e1efb0de129d93c7bb16f0e4b80a1a10d0409ed52bcd0df0b5511f6e08f74715517e9406edd45d78f0ef15d92b27ef398ea7bf9365fa13591322149fa84635187da277f15cbc8c9a28423feb233221e5d1ad36d926d2e1e0c770f34dc04a616f55685222a9b1cf4f8ecf87c19b7e03818500028181008cafd9654ce51818e154613bd0b14ee974fbdffc5a19802c4301302bc854d5e17daf0d6745a4aaa8e46ff96b57c89371fa72cca12a2248821645d1ff75869a2549ad7fd110ceefea5616d00be5941036e1a2d87bbcf0bfbe6c3b1e18ba0d3b3af6d34bacf613270a0b5f67c78668e4ba5b3ec0aa28e762ea1f9f2e0167e0523ba350304e301d0603551d0e04160414b0a8b5b2d1e7a5291a742ea6ee0f1cf0d1d45b4a301f0603551d23041830168014b0a8b5b2d1e7a5291a742ea6ee0f1cf0d1d45b4a300c0603551d13040530030101ff300b0609608648016503040302032f00302c02147ff6dde28ad40095342cdbf2e5e2621ed30db85d021422c71bc20564bd68beecf2f631cd0e3f3c649430"; // d1.self.cer.der

/*
// This works only on FF. Fail on Chrome.
test("variable assignment test1", function() {
var [a, b] = [3, 5];
expect(2);
equal(a, 3, "a 3");
equal(b, 5, "b 5");
});
 */

test("parse signature", function() {
  var s = "302c02146e41015afd8597894f42f466dde2190ebba6f15e0214787f9380a3a33011c88bf877df7ac3b8a62b854c";
  var dsa = new KJUR.crypto.DSA();
  var result = dsa.parseASN1Signature(s);
  expect(2);
  ok(result[0].compareTo(new BigInteger("6e41015afd8597894f42f466dde2190ebba6f15e", 16)) == 0, "s1");
  ok(result[1].compareTo(new BigInteger("787f9380a3a33011c88bf877df7ac3b8a62b854c", 16)) == 0, "s2");
});

test("verifyWithMessageHash d1.sig.aaa.1", function() {
  var sHashHex = KJUR.crypto.Util.hashString("aaa", "sha1");
  var hSigVal = "302c02146e41015afd8597894f42f466dde2190ebba6f15e0214787f9380a3a33011c88bf877df7ac3b8a62b854c";
  var dsa = new KJUR.crypto.DSA();
  dsa.setPublic(p, q, g, y);
  ok(dsa.verifyWithMessageHash(sHashHex, hSigVal), "v1");
});

test("verifyWithMessageHash d1.sig.aaa.2", function() {
  var sHashHex = KJUR.crypto.Util.hashString("aaa", "sha1");
  var hSigVal = "302c0214172fec83363f27ee5885c2a1a1bc228e07fcac4b021439e52cfa9d4226a444fee65330de760dda7904b2";
  var dsa = new KJUR.crypto.DSA();
  dsa.setPublic(p, q, g, y);
  ok(dsa.verifyWithMessageHash(sHashHex, hSigVal), "");
});

test("verifyWithMessageHash d1.sig.aaa.3", function() {
  var sHashHex = KJUR.crypto.Util.hashString("aaa", "sha512");
  var hSigVal = "302c021478a2596229442d899a973e07014d41901d6687cc0214407fb52627f287bef7e4f84f7d2582fa47cc26b3";
  var dsa = new KJUR.crypto.DSA();
  dsa.setPublic(p, q, g, y);
  ok(dsa.verifyWithMessageHash(sHashHex, hSigVal), "");
});

test("verifyWithMessageHash d1.sig.aaa.4", function() {
  var sHashHex = KJUR.crypto.Util.hashString("aaa", "sha512");
  var hSigVal = "302c02143605f5f1aba1a7e877847dc8d0d0c9bbf2886c2e02146c491c95f9fca3a0596e5fe6ad170db9fb11e15a";
  var dsa = new KJUR.crypto.DSA();
  dsa.setPublic(p, q, g, y);
  ok(dsa.verifyWithMessageHash(sHashHex, hSigVal), "");
});

test("signWithMessageHash test1", function() {
  var sHashHex = KJUR.crypto.Util.hashString("aaa", "sha1");
  var dsa = new KJUR.crypto.DSA();
  dsa.setPrivate(p, q, g, y, x);
  var result = dsa.signWithMessageHash(sHashHex).substr(0, 8);
  equal(result == "302c0214" || result == "302d0214", true, "heading 302[cd]0214");
});

test("sign and verifyWithMessageHash test1", function() {
  var sHashHex = KJUR.crypto.Util.hashString("aaa", "sha1");
  var dsa = new KJUR.crypto.DSA();
  dsa.setPrivate(p, q, g, y, x);
  var hSigVal = dsa.signWithMessageHash(sHashHex);

  var dsa2 = new KJUR.crypto.DSA();
  dsa2.setPublic(p, q, g, y);
  ok(dsa2.verifyWithMessageHash(sHashHex, hSigVal), "");
});

test("readPKCS5PrvKeyHex d1", function() {
  var key = new KJUR.crypto.DSA();
  key.readPKCS5PrvKeyHex(D1PRVP5HEX);
  equal(key.isPublic, false, "isPublic");
  equal(key.isPrivate, true, "isPrivate");
  equal(p.compareTo(key.p), 0, "P");
  equal(q.compareTo(key.q), 0, "Q");
  equal(g.compareTo(key.g), 0, "G");
  equal(y.compareTo(key.y), 0, "Y");
  equal(x.compareTo(key.x), 0, "X");
});

test("readPKCS8PrvKeyHex d1", function() {
  var key = new KJUR.crypto.DSA();
  key.readPKCS8PrvKeyHex(D1PRVP8HEX);
  equal(key.isPublic, false, "isPublic");
  equal(key.isPrivate, true, "isPrivate");
  equal(p.compareTo(key.p), 0, "P");
  equal(q.compareTo(key.q), 0, "Q");
  equal(g.compareTo(key.g), 0, "G");
  equal(key.y, null, "Y");
  equal(x.compareTo(key.x), 0, "X");
});

test("readPKCS8PubKeyHex d1", function() {
  var key = new KJUR.crypto.DSA();
  key.readPKCS8PubKeyHex(D1PUBP8HEX);
  equal(key.isPublic, true, "isPublic");
  equal(key.isPrivate, false, "isPrivate");
  equal(p.compareTo(key.p), 0, "P");
  equal(q.compareTo(key.q), 0, "Q");
  equal(g.compareTo(key.g), 0, "G");
  equal(y.compareTo(key.y), 0, "Y");
  equal(key.x, null, "X");
});

test("readCertPubKeyHex d1", function() {
  var key = new KJUR.crypto.DSA();
  key.readCertPubKeyHex(D1CERTHEX);
  equal(key.isPublic, true, "isPublic");
  equal(key.isPrivate, false, "isPrivate");
  equal(p.compareTo(key.p), 0, "P");
  equal(q.compareTo(key.q), 0, "Q");
  equal(g.compareTo(key.g), 0, "G");
  equal(y.compareTo(key.y), 0, "Y");
  equal(key.x, null, "X");
});

});
-->
</script>
  
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>
<p>
<a href="../">TOP</a> | 
<a href="index.html">TEST INDEX</a> | 
<a href="qunit-do-dsa.html">dsa2.js</a> | 
<a href="qunit-do-crypto-siginidsa.html">crypto.js for dsa2.js</a> | 
<a href="qunit-do-keyutil.html">keyutil</a> | 
<a href="qunit-do-keyutil-eprv.html">keyutil-eprv</a> | 
<a href="qunit-do-keyutil-pub.html">keyutil-pub</a> | 
</p>
</body>
</html>
